package edu.hawaii.solardecathlon.page.cooling;

import java.awt.Color;
import java.util.Map;
import org.apache.wicket.Resource;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource;
import org.apache.wicket.markup.html.link.Link;
import edu.hawaii.solardecathlon.page.BasePage;
import edu.hawaii.solardecathlon.page.images.DesignSet;

/**
 * The application cooling page.
 * 
 * @author Arthur Lee
 */
public class CoolingPage extends BasePage {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * The cooling page for this application.
   */
  public CoolingPage() {
    
    final String cooling_str = "cooling";
    final String cur_room_str = "cur_room";
    DesignSet room = new DesignSet();
    Map<String, String> props = getSessionProperties(cooling_str);
    //Prototyping
    props.put("cur_mode", "Manual");

    add(new Label("top_header", "Select the room you wish to configure."));
    
    //Add all the links and images for the map of the home.
    add(new Link<String>("room01Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Room");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("room", room.design_02)));
    add(new Link<String>("room02Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Natural Space");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("natural_space", room.design_03)));
    add(new Link<String>("room03Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Bathroom");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("bathroom", room.design_04)));
    add(new Link<String>("room04Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Kitchen");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("kitchen", room.design_05)));
    add(new Link<String>("room05Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Living/Dining/Sleeping");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("living", room.design_06)));
    add(new Link<String>("room06Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(cooling_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Entrance");
        //setResponsePage(new CoolingPage());
      }
    }
    .add(new Image("entrance", room.design_07)));
    
    //Buttons to turn on and off the A/C and scheduler.
    Image onButton = new Image("On", new ResourceReference("On") {
      private static final long serialVersionUID = 1L;
      protected Resource newResource() {
        DefaultButtonImageResource image = new DefaultButtonImageResource("ON");
        image.setColor(Color.orange);
        image.setTextColor(Color.white);
        return image;
      }
    });
    add(onButton);
    
    Image offButton = new Image("Off", new ResourceReference("Off") {
      private static final long serialVersionUID = 1L;
      protected Resource newResource() {
        DefaultButtonImageResource image = new DefaultButtonImageResource("OFF");
        image.setColor(Color.gray);
        image.setTextColor(Color.white);
        return image;
      }
    });
    add(offButton);
    
    //Add (fake) sliders so that user can adjust temperature and humidity settgins.
    add(new Image("SliderFull", new ResourceReference(CoolingPage.class, 
        "../media/fullbar.png")));
    add(new Image("SliderEmpty", new ResourceReference(CoolingPage.class, 
        "../media/emptybar.png")));
    
    //Buttons to save a schedule and clear a schedule.
    add(new Button("submit") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking the submit button, save settings. */
      @Override
      public void onSubmit() {
        // TODO
        // setResponsePage(SecurityPage.class);
      }
    });
    add(new Button("Clear") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking the submit button, save settings. */
      @Override
      public void onSubmit() {
        // TODO
        // setResponsePage(SecurityPage.class);
      }
    });
  }
}
